#include <bits/stdc++.h>
using namespace std;

int main() {
//    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    string line;
    while(getline(cin, line)){
        cout << line << "\n";
        stringstream ss(line);
        vector<int> A;
        int a;
        while(ss >> a) A.push_back(a);

        vector<int> ans;
        for (int p = A.size()-1; p > 0 ; --p) {
            int bigpos = max_element(A.begin(), A.begin()+p+1)-A.begin();
            if(bigpos == p) continue;
            if(bigpos != 0) {reverse(A.begin(), A.begin()+bigpos+1); ans.push_back(A.size() - bigpos);}
            reverse(A.begin(), A.begin()+p+1);
            ans.push_back(A.size() - p);
        }

        for (int i = 0; i < ans.size(); ++i) {
            cout << ans[i] << " ";
        }

        cout << 0 << "\n";
    }
    return 0;
}